import store from "@/store/store";
import { escapeHtml } from "./escapeHtml";
export default {
  richtext: {
    bind: function (el, binding, vnode) {
      // console.log("TCL:el", el);
      // console.log("TCL:binding", binding);
      // console.log("TCL:vnode", vnode);
      el.innerHTML = escapeHtml(binding.value);
    },
    componentUpdated: function (el, binding, vnode) {
      el.innerHTML = escapeHtml(binding.value);
    },
  },
  hasRole: {
    //调用全局组件控制按钮权限
    inserted: function (el, binding) {
      let roles = store.state.userInfo.roles || ["user"];
      if (!roles.includes(binding.value)) {
        el.parentNode.removeChild(el); //拿上级节点删除本级
      }
    },
  },
  hasPermission: {
    inserted: function (el, binding, vnode) {
      let value = binding.value;
      let types = vnode.context.$route.meta.types;
      let flag = true;
      for (let v of value) {
        if (!types.includes(v)) {
          flag = false;
        }
      }
      if (!flag) {
        el.parentNode.removeChild(el);
      }
    },
  },
};
